package com.cloud.code.真题;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * 股票收益
 */
public class Demo4 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        while (scanner.hasNext()){

            String line = scanner.nextLine();
            String[] strings = line.split(" ");
            List<Integer> list = new ArrayList<>();

            for (int si = 0; si < strings.length; si++) {
                String str = strings[si];
                int parseInt = Integer.parseInt(str.substring(0, str.length() - 1));
                if(str.contains("S")){
                    Integer pric = parseInt*7;
                    list.add(pric);
                }else {
                    Integer pric = parseInt;
                    list.add(pric);
                }
            }

            int max = Integer.MIN_VALUE;
            for (int i = 0; i < list.size(); i++) {
                int pri = list.get(i);
                int maxt = 0;
                for (int j = i+1; j < list.size(); j++) {
                    int prij = list.get(j);
                    if(prij>pri){
                        maxt = maxt + list.get(j)-pri;
                    }
                    pri = list.get(j);
                }
                max = Math.max(max,maxt);
            }

            System.out.println(max);

        }
    }
}
